/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Button, Text, TextArea, useTheme, useToast,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {setupItemAreaRoute} from "./orcIspConfig";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {EachMeasureCritConfig} from "../../common/msCriteria";
import {config绝缘阻, config行驶速度, config路线坡度, config踏板力, config驻车制力, render2轮距} from "../tour/orcBase";
import {itemA结论} from "../../lift/hydlicDj/editor";
import {itemA技术见证} from "../../elevator/stest/editor";
import {config制动距离, itemA制动距离} from "../tour/BrakingDistance";

export const 试验条件选=["符合要求","不符合要求"];
export const config设备概况 = [
    [['产品名称', '_$设备名称'], ['单位内编号','_$单位内部编号'], ],
    [['产品型号', '_$型号'],  ['产品编号', '_$出厂编号'], ],
    [['额定载客人数',{n:'载客人数',t:'n',u:'人'}], ['整机整备质量', '_$自重量','kg'] ],
    [['传动方式', '_$传动方式'], ['发动机（电机）编号', '_$发动机号'] ],
    [['车架编号', '_$底盘编号'], ['发动机（电机）功率', '_$主机功率','kW'] ],
    [['车牌编号','_$上路号牌'], ['制造日期', '_$制造日期'] ],
    [['动力方式','_$动力方式'], ['最大行驶坡度', '_$最大行驶坡度','%'] ],
    //+ _$前轮轮距     前： 后：
    [['最大行驶速度','_$最大行驶速度', 'km/h'], ['轮距（mm）','_$后轮轮距', render2轮距 ] ],
    [['观光列车车厢数','_$车厢数','节'], ['观光列车每节车厢座位数', '_$车厢座位数','个'] ],
    [['观光列车牵引车头座位数','_$车头座位数','个'], ['检验类别', '_$检验类别'] ],
    [['使用单位联系人', '_$单位联系人'],  ['现场试验条件', {n:'试验条',t:'l',l:试验条件选}], ],
    [['联系手机','_$使用单位电话'],  ['轴距', {n:'轴距',t:'n',u:'mm'}, ], ],
    [['检验意见通知书编号','意通知号'],  ['使用单位邮编','_$使用单位邮编']  ],
    [['使用单位地址', '_$使用单位地址'] ],
    [['分支机构地址', '_$分支机构地址'] ],
    [['产权单位','_$产权单位'], ],
    [['制造单位', '_$制造单位'], ],
    [['改造单位','_$改造单位'], ],
    [['现场检验条件',{r:'见附录B'}] ],
    [['检验依据',{r:'参照 TSG 81-2022 《场（厂）内专用机动车辆安全技术规程》'}]],
];

export const config观测数据 = [
    [{n: '蓄金电隙', t: ['2.7','(4)','蓄电池金属盖或者非金属盖的金属部件与蓄电池带电部分之间的间隙'], u: 'mm',c: '四', d: '0',cit:'30 ＜ X'}, ],
    [{n: '盖绝隙', t: [undefined,undefined,'若盖板和带电部分被有效绝缘时的间隙'], c: '四', d: '0', cit:'10 ≤ X'},  ],
    [{check: '2.7(4)', }],
    [{n: '胎壁割长', t: ['2.9','(3)', '充气轮胎胎面和胎壁存在破裂和割伤长度'],  c: '四', d: '2', cit:'X ≤ 25'},  ],
    [{check: '2.9(3)'}],
      //原版本2.11的
    [{n: '扶手高', t: ['2.13','(3)','扶手距离座椅上表面高度'],  c: '四',d: '0',cit:'180 ≤ X'}, ],
    [{check: '7.28'}],
] as EachMeasureCritConfig[][];

export const EntranceSetup =
    React.forwardRef((
        {show, alone = true, verId, rep}: InternalItemProps, ref
) => {
    const theme = useTheme();
    const atPrint = useMedia('print');
    const toast = useToast();
    const doCheckNames = React.useCallback((verId: string) => {
        const impressionismAs = setupItemAreaRoute({rep, noDefault: true, theme});
        const result = assertNamesUnique([{value: rep?.tzFields}, {value: impressionismAs?.Item, type: 'impr'},
            {value: config设备概况, type:'esnt'},
            {value:[...itemA结论, ...itemA技术见证, ] },
            {value: config观测数据, type:'mesB'}, {value: config路线坡度, type:'mesB'}, {value: config行驶速度, type:'mesB'}, {value: config驻车制力, type:'mesB'},
            {value: config制动距离, type:'mesB'}, {value:[...itemA制动距离, ] }, {value: config踏板力, type:'mesB'}, {value: config绝缘阻, type:'mesB'},
            {value:['unq','仪器表','检验条件', ]} ]);
        toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
    }, [rep,toast,theme]);
    const {storage, setStorage} =React.useContext(EditStorageContext) as any;
    const getInpFilter = React.useCallback((par: any) => {
        const {_tblFixed, } =par||{};
        return {_tblFixed, };
    }, []);
    const {inp, setInp} = useItemInputControl({ref});
    if (atPrint) return null;
    else return (
        <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show} alone={alone} label={'初始化本报告，默认值配置等'}>
            {process.env.REACT_APP_TEST==='true' && <><div>
                <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                <Text variant="h5">设置待测试表格的各列宽度：</Text>
                <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                    JSON.parse(e.currentTarget.value??'[]');
                    setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
            </div>
            </>
            }
            <hr/>
        </InspectRecordLayout>
    );
});
